package com.joey.preOrLazyInit;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class start {
    public static void main(String[] args) {
        //饿汉模式，预加载

        //就在加载配置文件时就把豆子实例化了，从而调用了构造方法
        ApplicationContext context = new ClassPathXmlApplicationContext("preOrLazyInit.xml");

        //可忽略
        //context.getBean("preOrLazyInit");



        //懒汉模式，懒加载

        //创建豆子厂
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        //将豆子厂和配置文件绑定（指定豆子厂的生产图纸）
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        reader.loadBeanDefinitions("preOrLazyInit.xml");

        //在豆子厂指定生产preOrLazyInit这个豆子
        //在生产时才会实例化豆子，跟着才会才会调用构造方法
        beanFactory.getBean("preOrLazyInit");
    }
}
